class Solution:
    def isPalindrome(self, s: str) -> bool:
        if not s:
            return True
        si = 0
        ei = len(s) - 1
        while si < ei:
            while True:
                if ('a' <= s[si] <= 'z') or ('A' <= s[si] <= 'Z') or ('0' <= s[si] <= '9'):
                    break
                si += 1
                if si == ei:
                    return True
            while True:
                if ('a' <= s[ei] <= 'z') or ('A' <= s[ei] <= 'Z') or ('0' <= s[ei] <= '9'):
                    break
                ei -= 1
                if si == ei:
                    return True

            if s[si].upper() != s[ei].upper():
                return False
            si += 1
            ei -= 1
        return True


if __name__ == '__main__':
    so = Solution()
    t = "A man1, a plan, a canal Panama"
    r = so.isPalindrome(t)
    print(r)
